package ma.ensao.evalmetrics.view.metrics.export;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import ma.ensao.evalmetrics.controller.CaracteristiquesManager;
import ma.ensao.evalmetrics.controller.MetriquesManager;
import ma.ensao.evalmetrics.controller.ProprieteManager;
import ma.ensao.evalmetrics.controller.ResultManager;
import ma.ensao.evalmetrics.controller.SubcaracManager;
import ma.ensao.evalmetrics.controller.rapportManager;
import ma.ensao.evalmetrics.controller.metrics.Calcule;
import ma.ensao.evalmetrics.model.Caracteristiques;
import ma.ensao.evalmetrics.model.Metriques;
import ma.ensao.evalmetrics.model.Propriete;
import ma.ensao.evalmetrics.model.Result;
import ma.ensao.evalmetrics.model.Subcarac;
import ma.ensao.evalmetrics.model.rapport;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFPicture;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.IOUtils;

import com.opensymphony.xwork2.ActionSupport;
/*
*Export les R�sultats des tests
*/
public class MetricsExportXls extends ActionSupport{
    Result resultMetrics= new Result();
    private Long idProjet;
    
    List<Result> liste;
	private Calcule calcule=new Calcule();
	private Result result;
	private Metriques metric ;
	private MetriquesManager metriquesmanager = new MetriquesManager();
	private Caracteristiques carac;
	private Subcarac sub;
	private Propriete propriete;
	private ProprieteManager proprietemanager=new ProprieteManager();
	private CaracteristiquesManager caracteristiques = new CaracteristiquesManager();
	private SubcaracManager subcarac = new SubcaracManager();
    private ResultManager resultmanager=new ResultManager();
    private rapport report;
    private rapportManager reportmanager;
    
        public MetricsExportXls() throws IOException {
            System.out.println("from constructeur");
           // MEXM= new MetricsExportXlsManager();
            //result= new ArrayList<Result>();
        }
        public void createXls() throws IOException{	
        	String image= "chart.jpg";
            HSSFWorkbook wb          = new HSSFWorkbook();
            FileOutputStream fileOut = new FileOutputStream("EvalMetrics_Rapport.xls");

			HSSFFont font = wb.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            HSSFCellStyle style = wb.createCellStyle();
            HSSFCellStyle style2 = wb.createCellStyle();
            HSSFCellStyle style3 = wb.createCellStyle();

            style2.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
            style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); 
            style3.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
            style3.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); 
            
            style.setBorderTop(CellStyle.BORDER_THIN);
            style.setTopBorderColor(IndexedColors.RED.getIndex());
            style.setBorderRight(CellStyle.BORDER_THIN);
            style.setRightBorderColor(IndexedColors.RED.getIndex());
            style.setBorderBottom(CellStyle.BORDER_THIN);
            style.setBottomBorderColor(IndexedColors.RED.getIndex());
            style.setBorderLeft(CellStyle.BORDER_THIN);
            style.setLeftBorderColor(IndexedColors.RED.getIndex());
            style.setBorderTop(CellStyle.BORDER_THIN);
            style.setTopBorderColor(IndexedColors.RED.getIndex());
            style.setFillForegroundColor(HSSFColor.ORANGE.index);
            style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);            style.setFont(font);
            
         // Create a new font and alter it.
            Font font2 = wb.createFont();
            font2.setFontHeightInPoints((short)16);
            font2.setFontName("Courier New");
            font2.setItalic(true);
            font2.setColor(HSSFColor.RED.index);
            
            // Fonts are set into a style so create a new one to use.
            HSSFCellStyle style4 = wb.createCellStyle();
            style4.setFont(font2);
            
            
         // Create a new font and alter it.
            Font font3 = wb.createFont();
            font3.setFontHeightInPoints((short)50);
            font3.setFontName("Courier New");
            font3.setItalic(true);
            font3.setColor(HSSFColor.RED.index);
            font3.setBoldweight(Font.BOLDWEIGHT_BOLD);
            
            // Fonts are set into a style so create a new one to use.
            HSSFCellStyle style5 = wb.createCellStyle();
            style5.setFont(font3);
            
          //HSSFSheet sheetFirst = wb.createSheet("Graphe Caract�ristiques");
            HSSFSheet sheetFirst = wb.createSheet("EM");
            HSSFSheet sheetMetrics = wb.createSheet("M�triques");
            HSSFSheet sheetProp = wb.createSheet("Propri�t�s");
            HSSFSheet sheetSubCara = wb.createSheet("Sous-Caract�ristiques");
            HSSFSheet sheetCara = wb.createSheet("Caract�ristiques");
            HSSFSheet sheetGraphe = wb.createSheet("Graphe Caract�ristiques");
            
            //sheetFirst= sheetFirst(wb, sheetFirst, image, style, style2, style3);
            sheetMetrics= sheetMetric(sheetMetrics, style, style2, style3);
            sheetProp= sheetProp(sheetProp, style, style2, style3);
            sheetSubCara= sheetSubCara(sheetSubCara, style, style2, style3);
            sheetCara= sheetCara(sheetCara, style, style2, style3);
            sheetGraphe= sheetGraphe(wb, sheetGraphe, image, style, style2, style3);
            sheetFirst= sheetFirst(wb, sheetFirst, style, style2, style3, style4, style5);

            wb.write(fileOut);
            fileOut.close();
        }
        public String execute() throws Exception {
        System.out.println("Hi from action");
        //result= MEXM.getResultMetrics(idProjet);
    	liste= resultmanager.MesResultat(idProjet);
        this.createXls();           
        return SUCCESS;
        }
        public Long getIdProjet() {
            return idProjet; 
        }
        public HSSFSheet sheetMetric(HSSFSheet sheet,  CellStyle style, CellStyle style2, CellStyle style3){
        	
        	HSSFRow[] row= new HSSFRow[liste.size()+1];//+1 la premiere ligne
            row[0] = sheet.createRow((short)0);
            row[0].createCell((short)0).setCellValue("Date du test");
            row[0].createCell((short)1).setCellValue("WMC");
            row[0].createCell((short)2).setCellValue("cyclo");
            row[0].createCell((short)3).setCellValue("VG");
            row[0].createCell((short)4).setCellValue("NOC");
            row[0].createCell((short)5).setCellValue("LOC");
            row[0].createCell((short)6).setCellValue("DIT");
            row[0].createCell((short)7).setCellValue("CLOC");
            row[0].createCell((short)8).setCellValue("NOM");
            row[0].createCell((short)9).setCellValue("POF");
            row[0].createCell((short)10).setCellValue("MHF");
            row[0].createCell((short)11).setCellValue("AHF");
            row[0].createCell((short)12).setCellValue("RFC");
            row[0].createCell((short)13).setCellValue("APF");
            row[0].createCell((short)14).setCellValue("Abs");
            row[0].createCell((short)15).setCellValue("MPC");
            row[0].createCell((short)16).setCellValue("TCC");
            row[0].createCell((short)17).setCellValue("MPF");
            row[0].createCell((short)18).setCellValue("NOI");
            //style
            row[0].getCell(0).setCellStyle(style);
			row[0].getCell(1).setCellStyle(style);
			row[0].getCell(2).setCellStyle(style);
			row[0].getCell(3).setCellStyle(style);
			row[0].getCell(4).setCellStyle(style);
			row[0].getCell(5).setCellStyle(style);
			row[0].getCell(6).setCellStyle(style);
			row[0].getCell(7).setCellStyle(style);
			row[0].getCell(8).setCellStyle(style);
			row[0].getCell(9).setCellStyle(style);
			row[0].getCell(10).setCellStyle(style);
			row[0].getCell(11).setCellStyle(style);
			row[0].getCell(12).setCellStyle(style);
			row[0].getCell(13).setCellStyle(style);
			row[0].getCell(14).setCellStyle(style);
			row[0].getCell(15).setCellStyle(style);
			row[0].getCell(16).setCellStyle(style);
			row[0].getCell(17).setCellStyle(style);
			row[0].getCell(18).setCellStyle(style);
			
            for(int i=1; i<= liste.size(); i++){
    			result=liste.get(i-1);
            	setMetric(metriquesmanager.list(idProjet).get(0));
    			setMetric(calcule.calculMetrique(metric, result));
                    row[i] = sheet.createRow((short)i);
                    for(int j=0; j<18; j++){
                        row[i].createCell((short)0).setCellValue(result.getDate().toString());
                        row[i].createCell((short)1).setCellValue(metric.getWMC());
                        row[i].createCell((short)2).setCellValue(metric.getCyclo());
                        row[i].createCell((short)3).setCellValue(metric.getVG());
                        row[i].createCell((short)4).setCellValue(metric.getNOC());
                        row[i].createCell((short)5).setCellValue(metric.getLOC());
                        row[i].createCell((short)6).setCellValue(metric.getDIT());
                        row[i].createCell((short)7).setCellValue(metric.getCLOC());
                        row[i].createCell((short)8).setCellValue(metric.getNOM());
                        row[i].createCell((short)9).setCellValue(metric.getPOF());
                        row[i].createCell((short)10).setCellValue(metric.getMHF());
                        row[i].createCell((short)11).setCellValue(metric.getAHF());
                        row[i].createCell((short)12).setCellValue(metric.getRFC());
                        row[i].createCell((short)13).setCellValue(metric.getAPF());
                        row[i].createCell((short)14).setCellValue(metric.getAbs());
                        row[i].createCell((short)15).setCellValue(metric.getMPC());
                        row[i].createCell((short)16).setCellValue(metric.getTCC());
                        row[i].createCell((short)17).setCellValue(metric.getMPF());
                        row[i].createCell((short)18).setCellValue(metric.getNOI());
                        if(i%2 == 0){
                        	for(int k = 0;k<=17; k++){
                        		if(k==0){
                        			row[i].getCell(k).setCellStyle(style);
                        		}else{
                        			row[i].getCell(k).setCellStyle(style2);
                        		}
                        	}
                        }else{
                        	for(int k = 0;k<=17; k++){
                        		if(k==0){
                        			row[i].getCell(k).setCellStyle(style);
                        		}else{
                        			row[i].getCell(k).setCellStyle(style3);
                        		}
                       	}
                        }

                    }
            }
        	sheet.setColumnWidth(0, 5000);

            return sheet;
        }
        public HSSFSheet sheetSubCara(HSSFSheet sheet,  CellStyle style, CellStyle style2, CellStyle style3){
        	HSSFRow[] row= new HSSFRow[liste.size()+1];//+1 la premiere ligne
            row[0] = sheet.createRow((short)0);
           
            for(int i=1; i<= liste.size(); i++){
    			result=liste.get(i-1);
    			sub = subcarac.list(idProjet).get(0);
				sub=calcule.calculSubcarac(sub);
    			
    			row[0].createCell((short)0).setCellValue("Date du test");
                row[0].createCell((short)1).setCellValue("Exactitude");
                row[0].createCell((short)2).setCellValue("Interoperabilite");
                row[0].createCell((short)3).setCellValue("Securite");
                row[0].createCell((short)4).setCellValue("Compliance");
                row[0].createCell((short)5).setCellValue("Maturite");
                row[0].createCell((short)6).setCellValue("FausseTolerance");
                row[0].createCell((short)7).setCellValue("Recoverabilite");
                row[0].createCell((short)8).setCellValue("Clarete");
                row[0].createCell((short)9).setCellValue("learnabilite");
                row[0].createCell((short)10).setCellValue("Attractivite");
                row[0].createCell((short)11).setCellValue("Comportement_time");
                row[0].createCell((short)12).setCellValue("Utilisation_Ressource");
                row[0].createCell((short)13).setCellValue("Variabilite");
                row[0].createCell((short)14).setCellValue("Analyse");
                row[0].createCell((short)15).setCellValue("Stabilite");
                row[0].createCell((short)16).setCellValue("Testabilite");
                row[0].createCell((short)17).setCellValue("Adabtabilite");
                row[0].createCell((short)18).setCellValue("Instabilite");
                row[0].createCell((short)19).setCellValue("Conformite");
                row[0].createCell((short)20).setCellValue("Remplaçabilite");
    			row[0].createCell((short)21).setCellValue("Convenance");
    			//style
    			row[0].getCell(0).setCellStyle(style);
    			row[0].getCell(1).setCellStyle(style);
    			row[0].getCell(2).setCellStyle(style);
    			row[0].getCell(3).setCellStyle(style);
    			row[0].getCell(4).setCellStyle(style);
    			row[0].getCell(5).setCellStyle(style);
    			row[0].getCell(6).setCellStyle(style);
    			row[0].getCell(7).setCellStyle(style);
    			row[0].getCell(8).setCellStyle(style);
    			row[0].getCell(9).setCellStyle(style);
    			row[0].getCell(10).setCellStyle(style);
    			row[0].getCell(11).setCellStyle(style);
    			row[0].getCell(12).setCellStyle(style);
    			row[0].getCell(13).setCellStyle(style);
    			row[0].getCell(14).setCellStyle(style);
    			row[0].getCell(15).setCellStyle(style);
    			row[0].getCell(16).setCellStyle(style);
    			row[0].getCell(17).setCellStyle(style);
    			row[0].getCell(18).setCellStyle(style);
    			row[0].getCell(19).setCellStyle(style);
    			row[0].getCell(20).setCellStyle(style);
    			row[0].getCell(21).setCellStyle(style);

                    row[i] = sheet.createRow((short)i);
                    for(int j=0; j<21; j++){
                    	row[i].createCell((short)0).setCellValue(result.getDate().toString());
                        row[i].createCell((short)1).setCellValue(sub.getExactitude());
                        row[i].createCell((short)2).setCellValue(sub.getInteroperabilite());
                        row[i].createCell((short)3).setCellValue(sub.getSecurite());
                        row[i].createCell((short)4).setCellValue(sub.getCompliance());
                        row[i].createCell((short)5).setCellValue(sub.getMaturite());
                        row[i].createCell((short)6).setCellValue(sub.getFausseTolerance());
                        row[i].createCell((short)7).setCellValue(sub.getRecoverabilite());
                        row[i].createCell((short)8).setCellValue(sub.getClarete());
                        row[i].createCell((short)9).setCellValue(sub.getLearnabilite());
                        row[i].createCell((short)10).setCellValue(sub.getAttractivite());
                        row[i].createCell((short)11).setCellValue(sub.getComportement_time());
                        row[i].createCell((short)12).setCellValue(sub.getUtilisation_Ressource());
                        row[i].createCell((short)13).setCellValue(sub.getVariabilite());
                        row[i].createCell((short)14).setCellValue(sub.getAnalyse());
                        row[i].createCell((short)15).setCellValue(sub.getStabilite());
                        row[i].createCell((short)16).setCellValue(sub.getTestabilite());
                        row[i].createCell((short)17).setCellValue(sub.getAdabtabilite());
                        row[i].createCell((short)18).setCellValue(sub.getInstabilite());
                        row[i].createCell((short)19).setCellValue(sub.getConformite());
                        row[i].createCell((short)20).setCellValue(sub.getRemplacabilite());
                    	row[i].createCell((short)21).setCellValue(sub.getConvenance());
                    	 if(i%2 == 0){
                         	for(int k = 0;k<=21; k++){
                         		if(k==0){
                        			row[i].getCell(k).setCellStyle(style);
                        		}else{
                        			row[i].getCell(k).setCellStyle(style2);
                        		}
                         	}
                         }else{
                         	for(int k = 0;k<=21; k++){
                         		if(k==0){
                        			row[i].getCell(k).setCellStyle(style);
                        		}else{
                        			row[i].getCell(k).setCellStyle(style3);
                        		}
                       	}
                        }

                    }
            }
        	sheet.setColumnWidth(0, 5000);
            return sheet;
        }
        public HSSFSheet sheetProp(HSSFSheet sheet,  CellStyle style, CellStyle style2, CellStyle style3){
        	HSSFRow[] row= new HSSFRow[liste.size()+1];//+1 la premiere ligne
            
        	row[0] = sheet.createRow((short)0);
			row[0].createCell((short)0).setCellValue("Date du test");
			row[0].createCell((short)1).setCellValue("coupling");
			row[0].createCell((short)2).setCellValue("abstraction");
			row[0].createCell((short)3).setCellValue("size");
			row[0].createCell((short)4).setCellValue("composition");
			row[0].createCell((short)5).setCellValue("encapsulation");
			row[0].createCell((short)6).setCellValue("modularite");
			row[0].createCell((short)7).setCellValue("precision");
			row[0].createCell((short)8).setCellValue("consistence");
			row[0].createCell((short)9).setCellValue("cohesion");
			row[0].createCell((short)10).setCellValue("tolerence");
			row[0].createCell((short)11).setCellValue("instabilite");
			row[0].createCell((short)12).setCellValue("dependence");
			row[0].createCell((short)13).setCellValue("complexite");
			row[0].createCell((short)14).setCellValue("message");
			row[0].createCell((short)15).setCellValue("specialisation");
			row[0].createCell((short)16).setCellValue("nbmethodes");
			row[0].createCell((short)17).setCellValue("sizemethodes");
			row[0].createCell((short)18).setCellValue("stabilite");
			row[0].createCell((short)19).setCellValue("heritage");
			//style
			row[0].getCell(0).setCellStyle(style);
			row[0].getCell(1).setCellStyle(style);
			row[0].getCell(2).setCellStyle(style);
			row[0].getCell(3).setCellStyle(style);
			row[0].getCell(4).setCellStyle(style);
			row[0].getCell(5).setCellStyle(style);
			row[0].getCell(6).setCellStyle(style);
			row[0].getCell(7).setCellStyle(style);
			row[0].getCell(8).setCellStyle(style);
			row[0].getCell(9).setCellStyle(style);
			row[0].getCell(10).setCellStyle(style);
			row[0].getCell(11).setCellStyle(style);
			row[0].getCell(12).setCellStyle(style);
			row[0].getCell(13).setCellStyle(style);
			row[0].getCell(14).setCellStyle(style);
			row[0].getCell(15).setCellStyle(style);
			row[0].getCell(16).setCellStyle(style);
			row[0].getCell(17).setCellStyle(style);
			row[0].getCell(18).setCellStyle(style);
			row[0].getCell(19).setCellStyle(style);
            for(int i=1; i<= liste.size(); i++){
    			result=liste.get(i-1);
    			propriete=proprietemanager.list(idProjet).get(0);
				propriete=calcule.calculPropriete(propriete);
				    			
                    row[i] = sheet.createRow((short)i);
                    for(int j=0; j<19; j++){
                    	 row[i].createCell((short)0).setCellValue(result.getDate().toString());
            			 row[i].createCell((short)1).setCellValue(propriete.getCoupling());
            			 row[i].createCell((short)2).setCellValue(propriete.getAbstraction());
            			 row[i].createCell((short)3).setCellValue(propriete.getSize());
            			 row[i].createCell((short)4).setCellValue(propriete.getComposition());
            			 row[i].createCell((short)5).setCellValue(propriete.getEncapsulation());
            			 row[i].createCell((short)6).setCellValue(propriete.getModularite());
            			 row[i].createCell((short)7).setCellValue(propriete.getPrecision());
            			 row[i].createCell((short)8).setCellValue(propriete.getConsistence());
            			 row[i].createCell((short)9).setCellValue(propriete.getCohesion());
            			 row[i].createCell((short)10).setCellValue(propriete.getTolerence());
            			 row[i].createCell((short)11).setCellValue(propriete.getInstabilite());
            			 row[i].createCell((short)12).setCellValue(propriete.getDependence());
            			 row[i].createCell((short)13).setCellValue(propriete.getComplexite());
            			 row[i].createCell((short)14).setCellValue(propriete.getMessage());
            			 row[i].createCell((short)15).setCellValue(propriete.getSpecialisation());
            			 row[i].createCell((short)16).setCellValue(propriete.getNbmethodes());
            			 row[i].createCell((short)17).setCellValue(propriete.getSizemethodes());
            			 row[i].createCell((short)18).setCellValue(propriete.getStabilite());                       
                    	 row[i].createCell((short)19).setCellValue(propriete.getHeritage());
                    	 if(i%2 == 0){
                          	for(int k = 0;k<=19; k++){
                          		if(k==0){
                        			row[i].getCell(k).setCellStyle(style);
                        		}else{
                        			row[i].getCell(k).setCellStyle(style2);
                        		}
                          	}
                          }else{
                          	for(int k = 0;k<=19; k++){
                          		if(k==0){
                        			row[i].getCell(k).setCellStyle(style);
                        		}else{
                        			row[i].getCell(k).setCellStyle(style3);
                        		}
                         	}
                          }
                    }
            }
            sheet.setColumnWidth(0, 5000);
            return sheet;
        }

        public HSSFSheet sheetCara(HSSFSheet sheet,  CellStyle style, CellStyle style2, CellStyle style3){
        	HSSFRow[] row= new HSSFRow[liste.size()+1];//+1 la premiere ligne
        	    row[0] = sheet.createRow((short)0);
        		row[0].createCell((short)0).setCellValue("Date du test");
                row[0].createCell((short)1).setCellValue("Reliabilite");
                row[0].createCell((short)2).setCellValue("Usabilite");
                row[0].createCell((short)3).setCellValue("Efficacite");
                row[0].createCell((short)4).setCellValue("Maintenabilite");
                row[0].createCell((short)5).setCellValue("Portabilite");
        		row[0].createCell((short)6).setCellValue("Fonctionnalite");
        		//style
        		row[0].getCell(0).setCellStyle(style);
    			row[0].getCell(1).setCellStyle(style);
    			row[0].getCell(2).setCellStyle(style);
    			row[0].getCell(3).setCellStyle(style);
    			row[0].getCell(4).setCellStyle(style);
    			row[0].getCell(5).setCellStyle(style);
    			row[0].getCell(6).setCellStyle(style);

            for(int i=1; i<= liste.size(); i++){
    			result=liste.get(i-1);
				carac=caracteristiques.list(idProjet).get(0);
				carac=calcule.calculCaracteristiques(carac);
                    row[i] = sheet.createRow((short)i);
                    for(int j=0; j<6; j++){
	 					row[i].createCell((short)0).setCellValue(result.getDate().toString());
                        row[i].createCell((short)1).setCellValue(carac.getReliabilite());
                        row[i].createCell((short)2).setCellValue(carac.getUsabilite());
                        row[i].createCell((short)3).setCellValue(carac.getEfficacite());
                        row[i].createCell((short)4).setCellValue(carac.getMaintenabilite());
                        row[i].createCell((short)5).setCellValue(carac.getPortabilite());
	 					row[i].createCell((short)6).setCellValue(carac.getFonctionnalite());
	 					if(i%2 == 0){
                         	for(int k = 0;k<=6; k++){
                         		if(k==0){
                        			row[i].getCell(k).setCellStyle(style);
                        		}else{
                        			row[i].getCell(k).setCellStyle(style2);
                        		}
                         	}
                         }else{
                         	for(int k = 0;k<=6; k++){
                         		if(k==0){
                        			row[i].getCell(k).setCellStyle(style);
                        		}else{
                        			row[i].getCell(k).setCellStyle(style3);
                        		}
                        	}
                         }
                    }
            }
            sheet.setColumnWidth(0, 5000);
            return sheet;
        }

        public HSSFSheet sheetGraphe(HSSFWorkbook wb, HSSFSheet my_sheet,String image,  CellStyle style, CellStyle style2, CellStyle style3) throws IOException{
			InputStream my_banner_image = new FileInputStream(image);
            /* Convert Image to byte array */
            byte[] bytes = IOUtils.toByteArray(my_banner_image);
            /* Add Picture to workbook and get a index for the picture */
            int my_picture_id = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
            /* Close Input Stream */
            my_banner_image.close();                
            /* Create the drawing container */
            HSSFPatriarch drawing = my_sheet.createDrawingPatriarch();
            /* Create an anchor point */
            ClientAnchor my_anchor = new HSSFClientAnchor();
            /* Define top left corner, and we can resize picture suitable from there */
            my_anchor.setCol1(2);
            my_anchor.setRow1(1);           
            /* Invoke createPicture and pass the anchor point and ID */
            HSSFPicture  my_picture = drawing.createPicture(my_anchor, my_picture_id);
            /* Call resize method, which resizes the image */
            my_picture.resize();    
            
            return my_sheet;
        }
        public HSSFSheet sheetStatistiques(HSSFWorkbook wb, HSSFSheet sheet,CellStyle style, CellStyle style2, CellStyle style3, CellStyle style4) throws IOException{
        	
        	report=new rapport();
        	reportmanager=new rapportManager();	
        	report=reportmanager.calculeRapport(report, idProjet);	

        	HSSFRow[] row= new HSSFRow[5];
        	row[0] = sheet.createRow((short)0);
    		row[0].createCell((short)0).setCellValue("Statistiques sur le projet : ");
    		
    		row[1] = sheet.createRow((short)1);
    		row[1].createCell((short)0).setCellValue("Nom : ");
            row[1].createCell((short)1).setCellValue(report.getNom());
            
    		row[2] = sheet.createRow((short)2);
     		row[2].createCell((short)0).setCellValue("Date de l'ajout : ");
            row[2].createCell((short)1).setCellValue(report.getDate_ajout().toString());
            row[3] = sheet.createRow((short)3);
    		row[3].createCell((short)0).setCellValue("Date du dernier test : ");
            row[3].createCell((short)1).setCellValue(report.getDate_dernier().toString());
            row[4] = sheet.createRow((short)4);
    		row[4].createCell((short)0).setCellValue("Nombre de tests effectu�s : ");
            row[4].createCell((short)1).setCellValue(report.getNbprojets());
            
            row[0].getCell(0).setCellStyle(style4);
            sheet.setColumnWidth(0, 10000);
            return sheet;
        }
        public HSSFSheet sheetFirst(HSSFWorkbook wb, HSSFSheet sheet, CellStyle style, CellStyle style2, CellStyle style3,CellStyle style4,CellStyle style5) throws IOException{
        	DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
     	    //get current date time with Date()
     	    Date date = new Date();
     	    System.out.println(dateFormat.format(date));
        	HSSFRow[] row= new HSSFRow[20];//+1 la premiere ligne
    	    row[5] = sheet.createRow((short)5);
    		row[5].createCell((short)3).setCellValue("EvalMetrics::Rapport");
            row[5].getCell(3).setCellStyle(style5);
            
           
          
            
            
            report=new rapport();
        	reportmanager=new rapportManager();	
        	report=reportmanager.calculeRapport(report, idProjet);	
    		
    		row[8] = sheet.createRow((short)8);
    		row[8].createCell((short)3).setCellValue("Nom : "+ report.getNom());
            
    		row[9] = sheet.createRow((short)9);
     		row[9].createCell((short)3).setCellValue("Date de l'ajout : "+ report.getDate_ajout().toString());
            row[10] = sheet.createRow((short)10);
    		row[10].createCell((short)3).setCellValue("Date du dernier test : "+ report.getDate_dernier().toString());
            row[11] = sheet.createRow((short)11);
    		row[11].createCell((short)3).setCellValue("Nombre de tests effectu�s : "+ report.getNbprojets());
            
            row[12] = sheet.createRow((short)12);
    		row[12].createCell((short)3).setCellValue("G�n�r� le: "+dateFormat.format(date));
            row[12].getCell(3).setCellStyle(style4);
            
            return sheet;
        }

        public void setIdProjet(Long idProjet) {
            this.idProjet = idProjet;
        }
		public Metriques getMetric() {
			return metric;
		}
		public void setMetric(Metriques metric) {
			this.metric = metric;
		}
		public Result getResultMetrics() {
			return resultMetrics;
		}
		public void setResultMetrics(Result resultMetrics) {
			this.resultMetrics = resultMetrics;
		}
		public List<Result> getListe() {
			return liste;
		}
		public void setListe(List<Result> liste) {
			this.liste = liste;
		}
		public Calcule getCalcule() {
			return calcule;
		}
		public void setCalcule(Calcule calcule) {
			this.calcule = calcule;
		}
		public Result getResult() {
			return result;
		}
		public void setResult(Result result) {
			this.result = result;
		}
		public MetriquesManager getMetriquesmanager() {
			return metriquesmanager;
		}
		public void setMetriquesmanager(MetriquesManager metriquesmanager) {
			this.metriquesmanager = metriquesmanager;
		}
		public ResultManager getResultmanager() {
			return resultmanager;
		}
		public void setResultmanager(ResultManager resultmanager) {
			this.resultmanager = resultmanager;
		}
		
		public Caracteristiques getCarac() {
			return carac;
		}
		public void setCarac(Caracteristiques carac) {
			this.carac = carac;
		}
		public Subcarac getSub() {
			return sub;
		}
		public void setSub(Subcarac sub) {
			this.sub = sub;
		}
		public Propriete getPropriete() {
			return propriete;
		}
		public void setPropriete(Propriete propriete) {
			this.propriete = propriete;
		}
		public ProprieteManager getProprietemanager() {
			return proprietemanager;
		}
		public void setProprietemanager(ProprieteManager proprietemanager) {
			this.proprietemanager = proprietemanager;
		}
		public CaracteristiquesManager getCaracteristiques() {
			return caracteristiques;
		}
		public void setCaracteristiques(CaracteristiquesManager caracteristiques) {
			this.caracteristiques = caracteristiques;
		}
		public SubcaracManager getSubcarac() {
			return subcarac;
		}
		public void setSubcarac(SubcaracManager subcarac) {
			this.subcarac = subcarac;
		}
		public rapport getReport() {
			return report;
		}
		public void setReport(rapport report) {
			this.report = report;
		}
		public rapportManager getReportmanager() {
			return reportmanager;
		}
		public void setReportmanager(rapportManager reportmanager) {
			this.reportmanager = reportmanager;
		}
}